var login_ops = {
    'init':function()
    {
        this.eventBind();
    },
    'eventBind':function()
    {
        $('#login-btn').on('click',function(){
            login();
        });
    }
};

$("body").on("keypress",function(e){
    var keycode=e.keyCode;
    if(keycode==13){
        login();
    }
})

function login(){
    var form = $('#form1'),
        username = $('#username').val(),
        pass = $('#pass').val();
    // if(!(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(email)))
    // {
    //     layer.alert('请输入正确邮箱号!');
    //     return false;
    // }

    if(!pass)
    {
        layer.alert('请输入密码!');
        return false;
    }

    $.ajax({
        'type':'POST',
        'url':'/admin/login',
        'data':form.serialize(),
        'dataType':'json',
        'beforeSend':function(){
            layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
        },
        'success':function(data)
        {
            layer.closeAll();
            if(data.code != 200)
            {
                layer.alert(data.msg);
                return false;
            }
            location.href = '/';
        }

    });
}

//查看进度
$('.look-progress').on('click',function () {
    ShowPhoneBox();
    //确定
    $('.update-shop').on('click',function () {
        var phone = $('.b-text').val();
        if(phone == ''){
            layer.alert('电话号码必填');
            return false;
        }
        $.ajax({
            'type':'POST',
            'url':'/shop/get-info',
            'data':{
                admin_phone:phone
            },
            'dataType':'json',
            'success':function(data)
            {
                layer.closeAll();
                if(data.code == 200)
                {
                    location.href = '/shop/update-shop?id='+data.data;
                    return false;
                }
                layer.alert(data.msg);
                location.href = '/';
            }

        });



    });

    //隐藏
    $('.close-hidden').on('click',function () {
        $('.b-div').hide();
    });


});

function ShowPhoneBox(){
    var dIv=$("<div class='b-div'><h4 class='b-h4'>提示</h4><p class='b-p'>请输入管理员电话</p><textarea class='b-text'></textarea><div class='b-btn'><input type='button' value='确认' class='b-confirm btn-primary update-shop'><input type='button' value='取消' class='b-cancel close-hidden'></div></div>");
    $("body").append(dIv);
};





$(document).ready(function(){
    login_ops.init();
});